<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>、
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/bootstrap/css/bootstrap.css"
          media="all">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/main.css" media="all">
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/common/bootstrap/js/jquery-1.12.4.js"></script>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/common/bootstrap/css/bootstrap-select.css">
</head>
<body>
    <div class="col-xs-3">
        <form  id="passwordform" method="post" action="">
            <input  id="userid" type="text" style="display:none;"value="${meaningUser.userId}" name="userId">
            <p>
                旧密码:<input type="password" class="form-control" placeholder="请输入原始密码"name="password" id="password1">
                <span id="sp"></span>
            </p>
            <p>
                新密码:<input type="password" class="form-control" placeholder="请输入新密码"name="password" id="password2">
                <span id="sp1"></span>
            </p>
            <p>
                确认新密码:<input type="password"  class="form-control" placeholder="请再输入一次新密码" id="password3">
                <span id="sp2"></span>
            </p>
            <div>
                <button type="button"  class="btn btn-primary" id="bc">保存</button>
                <span id="bt"></span>
            </div>
        </form>
    </div>
</body>
<script type="text/javascript">
$(function () {
    $("#password1").blur(function () {
        var pw=$("#password1").val();
        var userid=$("#userid").val();
        console.log(pw);
        console.log(userid);
        $.ajax({
            url :"../../loginRegistered/eq",
            type : "post",
            dataType :"json",
            data:{
                password:pw,
                id:userid,
            },
            success:function(result){
                console.log("密码验证："+result);
                if(result==1){
                    $("#sp").text("密码输入正确").css('color','green');
                }else if(result==2){
                    $("#sp").text("您输入密码错误请重新输入").css('color','red');
                    $("#password1").text("");
                }
            }
        })
    })

    $("#password2").blur(function () {
        var str = $("#password2").val();
        var patrn = /^(\w){6,20}$/;
        if (patrn.test(str) == false) {
            $("#sp1").text("密码输入格式有误").css("color", "red");
        }else{
            $("#sp1").text("密码输入正确").css("color", "green");
        }
    })
    $("#password3").blur(function () {
        var p1= $("#password2").val();
        var p2= $("#password3").val();
        if (p1 != p2){
            $("#sp2").text("俩次输入的密码不一致").css("color", "red");
        } else{
            $("#sp2").text("密码输入正确").css("color", "green");
        }
    })
    //保存修改密码
    $("#bc").click(function () {
        var userid=$("#userid").val();
        var pw= $("#password3").val();
        $.ajax({
            url :"/upMeaningUser",
            type : "post",
            dataType :"json",
            data:{
                password:pw,
                userId:userid,
            },
            success:function(result){
                if (result !=null){
                    $("#bt").text("修改密码成功").css("color", "green");
                    top.location.href="/tzlogin";
                }else{
                    $("#bt").text("修改密码失败").css("color", "red");
                }
            },
            error:function () {
                $("#bt").text("系统异常").css("color", "red");
            }
        })
    })
})
</script>
</html>